package com.uzai.console.web.takebal;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.google.common.collect.Lists;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.common.enums.TakeBalStatusEnum;
import com.uzai.common.enums.TransTypeEnum;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.takebal.usertakebal.*;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.takebal.UserTakeBalService;
import com.uzai.console.service.takebal.UserTakeBalSyncService;
import com.uzai.console.vo.alipaymchbatch.AlipayMchBatchTransVo;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.takebal.usertakebal.*;
import com.uzai.console.web.BaseController;
import com.uzai.console.web.user.WechatUserContoller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author liuqi
 * @date 2021年08月30日 13:32
 */
@Api(value = "提现列表",tags = "提现管理|提现列表")
@ApiSort(16)
@RestController
public class UserTakeBalController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(WechatUserContoller.class);

    @Autowired
    private UserTakeBalService userTakeBalService;
    @Autowired
    private UserTakeBalSyncService userTakeBalSyncService;

    @ApiOperation(value = "查询用户类型下拉列表框", notes = "查询用户类型下拉列表框", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/userTakeBal/findUserDeviceTypeList")
    public Object findUserDeviceTypeList(){
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        SelectKeyVo selectKeyVo_pc = new SelectKeyVo();
        selectKeyVo_pc.setKey(DeviceTypeEnum.DT_PC_WECHAT.getKey());
        selectKeyVo_pc.setValue("个人微信用户");
        selectKeyVo_pc.setIsDefault(1);
        selectKeyVoList.add(selectKeyVo_pc);

        SelectKeyVo selectKeyVo_work = new SelectKeyVo();
        selectKeyVo_work.setKey(DeviceTypeEnum.DT_WORK_WECHAT.getKey());
        selectKeyVo_work.setValue("企业微信用户");
        selectKeyVoList.add(selectKeyVo_work);

        SelectKeyVo selectKeyVo_pub = new SelectKeyVo();
        selectKeyVo_pub.setKey(DeviceTypeEnum.WX_PUB.getKey());
        selectKeyVo_pub.setValue("公众号用户");
        selectKeyVoList.add(selectKeyVo_pub);

        SelectKeyVo selectKeyVo_mini = new SelectKeyVo();
        selectKeyVo_mini.setKey(DeviceTypeEnum.MINI_PRO.getKey());
        selectKeyVo_mini.setValue("小程序用户");
        selectKeyVoList.add(selectKeyVo_mini);

        return selectKeyVoList;
    }

    @ApiOperation(value = "查询提现状态下拉列表框", notes = "查询提现状态下拉列表框", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/userTakeBal/findUserTakeBalStatusList")
    public Object findUserTakeBalStatusList(){
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        for (TakeBalStatusEnum takeBalStatusEnum : TakeBalStatusEnum.values()){
            SelectKeyVo selectKeyVo = new SelectKeyVo();
            selectKeyVo.setKey(String.valueOf(takeBalStatusEnum.getValue()));
            selectKeyVo.setValue(takeBalStatusEnum.getDesc());
            selectKeyVoList.add(selectKeyVo);
        }
        return selectKeyVoList;
    }

    @ApiOperation(value = "查询提现支付方式下拉列表框", notes = "查询提现支付方式下拉列表框", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 2)
    @PostMapping("/userTakeBal/findUserTakeBalTransTypeList")
    public Object findUserTakeBalTransTypeList(){
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        for (TransTypeEnum transTypeEnum : TransTypeEnum.values()){
            SelectKeyVo selectKeyVo = new SelectKeyVo();
            selectKeyVo.setKey(String.valueOf(transTypeEnum.getValue()));
            selectKeyVo.setValue(transTypeEnum.getDesc());
            selectKeyVoList.add(selectKeyVo);
        }
        return selectKeyVoList;
    }

    @ApiOperation(value = "分页查询提现列表", notes = "分页查询提现列表", response = UserTakeBalPageVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/userTakeBal/findUserTakeBalList")
    public Object findUserTakeBalList(@RequestBody UserTakeBalQuery userTakeBalQuery){
        return userTakeBalService.findUserTakeBalList(userTakeBalQuery);
    }

    @ApiOperation(value = "查询提现详情", notes = "查询提现详情", response = UserTakeBalPageVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/userTakeBal/findUserTakeBalInfo")
    public Object findUserTakeBalInfo(@RequestBody UserTakeBalIdDto userTakeBalIdDto){
        return userTakeBalService.findUserTakeBalInfo(userTakeBalIdDto);
    }

    @ApiOperation(value = "自动设置下一条提现详情开关", notes = "自动设置下一条提现详情开关", response = UserTakeBalPageVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/userTakeBal/next/setFlag")
    public Object setNextFlag(@RequestBody UserTakeBalNexSetDto userTakeBalNexSetDto){
        userTakeBalService.setNextFlag(userTakeBalNexSetDto);
        return true;
    }

    @ApiOperation(value = "查询下一条提现详情", notes = "查询下一条提现详情", response = UserTakeBalPageVo.class)
    @ApiOperationSupport(order = 3)
    @PostMapping("/userTakeBal/findUserTakeBalInfo/next")
    public Object findNextUserTakeBalInfo(@RequestBody UserTakeBalQuery userTakeBalQuery){
        //默认只查询状态为未处理的订单
        userTakeBalQuery.setStatus(TakeBalStatusEnum.TBS_PENDING.getValue());
        return userTakeBalService.findNextUserTakeBalInfo(userTakeBalQuery);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "通过审核", notes = "通过审核", response = Boolean.class)
    @ApiOperationSupport(order = 4)
    @PostMapping("/userTakeBal/checkUserTakeBal")
    public Object checkUserTakeBal(@RequestBody UserTakeBalIdDto userTakeBalIdDto){
        userTakeBalService.checkUserTakeBal(userTakeBalIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "拒绝并返还", notes = "拒绝并返还", response = Boolean.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/userTakeBal/refuseAndReturnUserTakeBal")
    public Object refuseAndReturnUserTakeBal(@RequestBody UserTakeBalIdDto userTakeBalIdDto){
        userTakeBalService.refuseAndReturnUserTakeBal(userTakeBalIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量拒绝并返还", notes = "批量拒绝并返还", response = UserTakeBatchRefuseAndReturnVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/userTakeBal/batchRefuseAndReturnUserTakeBal")
    public Object batchRefuseAndReturnUserTakeBal(@RequestBody UserTakeBalIdListDto userTakeBalIdListDto){
        return userTakeBalSyncService.batchRefuseAndReturnUserTakeBal(userTakeBalIdListDto);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "拒绝并扣除", notes = "拒绝并扣除", response = Boolean.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/userTakeBal/refuseAndDecUserTakeBal")
    public Object refuseAndDecUserTakeBal(@RequestBody UserTakeBalIdDto userTakeBalIdDto){
        userTakeBalService.refuseAndDecUserTakeBal(userTakeBalIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量拒绝并扣除", notes = "批量拒绝并扣除", response = UserTakeBatchRefuseAndDecUserVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/userTakeBal/batchRefuseAndDecUserTakeBal")
    public Object batchRefuseAndDecUserTakeBal(@RequestBody UserTakeBalIdListDto userTakeBalIdListDto){
        return userTakeBalSyncService.batchRefuseAndDecUserTakeBal(userTakeBalIdListDto);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "发送提现卡片", notes = "发送提现卡片", response = Boolean.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/userTakeBal/sendcard")
    public Object sendcard(@RequestBody UserTakeBalSendCardDto userTakeBalSendCardDto){
        userTakeBalService.sendcard(userTakeBalSendCardDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "提现微信转账", notes = "提现微信转账", response = Boolean.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/userTakeBal/wxpay")
    public Object wxpay(@RequestBody UserTakeBalIdDto userTakeBalIdDto){
        userTakeBalService.wxpay(userTakeBalIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "提现微信红包(仅手机版支持)", notes = "提现微信红包(仅手机版支持)", response = Boolean.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/userTakeBal/wxRedpacket")
    public Object wxRedpacket(@RequestBody UserTakeBalIdDto userTakeBalIdDto){
        userTakeBalService.wxRedpacket(userTakeBalIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "提现支付宝转账(账房)", notes = "提现支付宝转账(账房)", response = Boolean.class)
    @ApiOperationSupport(order = 9)
    @PostMapping("/userTakeBal/alipay")
    public Object alipay(@RequestBody UserTakeBalIdDto userTakeBalIdDto){
        userTakeBalService.alipay(userTakeBalIdDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "提现支付宝转账(个人)", notes = "提现支付宝转账(个人)", response = AlipayMchBatchTransVo.class)
    @ApiOperationSupport(order = 9)
    @PostMapping("/userTakeBal/alipayMch")
    public Object alipayMch(@RequestBody UserTakeBalAlipayMchDto userTakeBalAlipayMchDto){
        return userTakeBalService.alipayMch(userTakeBalAlipayMchDto);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量提现支付宝转账(个人)", notes = "批量提现支付宝转账(个人)", response = AlipayMchBatchTransVo.class)
    @ApiOperationSupport(order = 13)
    @PostMapping("/userTakeBal/batchAlipayMch")
    public Object batchAlipayMch(@RequestBody UserTakeBalAlipayMchBatchDto userTakeBalAlipayMchBatchDto){
        return userTakeBalSyncService.batchAlipayMch(userTakeBalAlipayMchBatchDto);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "查询支付结果", notes = "查询支付结果", response = Boolean.class)
    @ApiOperationSupport(order = 10)
    @PostMapping("/userTakeBal/queryResult")
    public Object queryResult(@RequestBody UserTakeBalIdDto userTakeBalIdDto){
        return userTakeBalService.queryResult(userTakeBalIdDto);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量发送提现卡片", notes = "批量发送提现卡片", response = UserTakeBatchSendcardVo.class)
    @ApiOperationSupport(order = 11)
    @PostMapping("/userTakeBal/batchSendcard")
    public Object batchSendcard(@RequestBody UserTakeBalSendCardListDto userTakeBalSendCardListDto){
        return userTakeBalSyncService.batchSendcard(userTakeBalSendCardListDto);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量提现微信转账", notes = "批量提现微信转账", response = UserTakeBatchWxpayVo.class)
    @ApiOperationSupport(order = 12)
    @PostMapping("/userTakeBal/batchWxpay")
    public Object batchWxpay(@RequestBody UserTakeBalIdListDto userTakeBalIdListDto){
        return userTakeBalSyncService.batchWxpay(userTakeBalIdListDto);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "批量提现支付宝转账(账房)", notes = "批量提现支付宝转账(账房)", response = UserTakeBatchAlipayVo.class)
    @ApiOperationSupport(order = 13)
    @PostMapping("/userTakeBal/batchAlipay")
    public Object batchAlipay(@RequestBody UserTakeBalIdListDto userTakeBalIdListDto){
        return userTakeBalSyncService.batchAlipay(userTakeBalIdListDto);
    }

    @ApiOperation(value = "查询待处理总金额", notes = "查询待处理总金额", response = UserTakeBalReportVo.class)
    @ApiOperationSupport(order = 14)
    @PostMapping("/userTakeBal/findUserTakeBalReport")
    public Object findUserTakeBalReport(@RequestBody UserTakeBalQuery userTakeBalQuery){
        userTakeBalQuery.setMerId(getLoginInfo().getMerId());
        userTakeBalQuery.setStatusList(Lists.newArrayList(TakeBalStatusEnum.TBS_PENDING.getValue(), TakeBalStatusEnum.TBS_AUTO_TAKEBAL_FAIL.getValue())); //待处理和自动提现失败
        return userTakeBalService.findUserTakeBalReport(userTakeBalQuery);
    }

    @ApiOperation(value = "查询提现总金额", notes = "查询提现总金额", response = UserTakeBalReportVo.class)
    @ApiOperationSupport(order = 14)
    @PostMapping("/userTakeBal/findUserTakeBalReportForTaked")
    public Object findUserTakeBalReportForTaked(@RequestBody UserTakeBalQuery userTakeBalQuery){
        userTakeBalQuery.setMerId(getLoginInfo().getMerId());
        userTakeBalQuery.setStatus(null);
        //自动提现成功和手动审核成功
        userTakeBalQuery.setStatusList(Arrays.asList(TakeBalStatusEnum.TBS_AUTO_TAKEBAL_SUCCESS.getValue(), TakeBalStatusEnum.TBS_MANUAL_AUDIT_SUCCESS.getValue()));
        return userTakeBalService.findUserTakeBalReport(userTakeBalQuery);
    }

    @SystemLogType(model = SystemModelEnum.UserTakeBal, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "修改提现备注", notes = "修改提现备注", response = Boolean.class)
    @ApiOperationSupport(order = 15)
    @PostMapping("/userTakeBal/updateRemark")
    public Object updateRemark(@RequestBody UserTakeBalUpdateRemarkDto userTakeBalUpdateRemarkDto){
        userTakeBalService.updateRemark(userTakeBalUpdateRemarkDto);
        return true;
    }




}
